package visitacolony;

public class UserMainCode {
	public static int house_condition(int[] S, int h) {
		int[] g = new int[S.length];
		g[0] = 1;
		g[1] = S[0] - g[0];
		for(int i = 2; i < h; i++)
			g[i] = S[i - 1] - g[i - 1] - g[i - 2];
		if(g[h - 1] < 0 || g[h - 1] > 1)
			return -1;
		return g[h - 1];
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] S1 = {2,2,1,1,1};
		System.out.println(house_condition(S1, 4));
		int[] S2 = {1,2,1,2,1,1,0};
		System.out.println(house_condition(S2, 3));
	}
}
